sc.ascfont
Like the FontManager but instead of drawing Bitmap fonts, it draws Outline fonts (eg, TTF, OTF and etc). This means it can draw with rotation, any font scale and etc!
And unlike the FontManager, It also lets you convert colors inside text into actual colors!
Structures
ASCFont
Represents a font and its associated metadata, glyphs, and other properties.
Fields:
metadata
[ ASCFont.Metadata ]glyphs
[ table ]: A table mapping glyph names to their corresponding glyph data.- Key [ string ] The glyph name.
- Value [ ASCFont.Glyph ] All glyphs in the font.
ASCFont.Metadata
Metadata related to the font, such as its names, ascender/descender values, and bounding box.
Fields:
names
[ table ] A table containing font names, like "PostScript" or "Full Name".Key
[ string ] The index (eg, fullname)Value
[ string ] The value
ascender
[ number ] The ascender value for the font, which is the height of the highest point of any character.descender
[ number ] The descender value for the font, which is the depth of the lowest point of any character.underLinePosition
[ number ] The vertical position where the underline is drawn.underLineThickness
[ number ] The thickness of the underline.boundingBox
[ ASCFont.BoundingBox ] The overall bounding box for the font, containing the maximum and minimum coordinates.resolution
[ number ] The resolution (typically in DPI) for the font.
ASCFont.BoundingBox
Represents the bounding box for a font, which defines the minimum and maximum x and y coordinates.
Fields:
xMin
[ number ] The minimum x-coordinate of the font's bounding box.xMax
[ number ] The maximum x-coordinate of the font's bounding box.yMin
[ number ] The minimum y-coordinate of the font's bounding box.yMax
[ number ] The maximum y-coordinate of the font's bounding box.
ASCFont.Glyph
Represents a single glyph in the font, which includes its width, metrics, and triangle data.
Fields:
advanceWidth
[ number ] The width of the glyph, which determines the spacing between it and the next character.metrics
[ ASCFont.Metrics ] The metrics associated with the glyph, including its bounding box and left bearing.triangles
[ ASCFont.Triangle[] ] A table of triangles that define the shape of the glyph.
ASCFont.Metrics
Represents the metrics for a glyph, extending from the bounding box with additional properties such as left bearing.
Based on: ASCFont.BoundingBox
Fields:
leftBearing
[ number ] The horizontal distance from the origin to the leftmost edge of the glyph's bounding box.xMin
[ number ] (From ASCFont.BoundingBox) The minimum x-coordinate of the font's bounding box.xMax
[ number ] (From ASCFont.BoundingBox) The maximum x-coordinate of the font's bounding box.yMin
[ number ] (From ASCFont.BoundingBox) The minimum y-coordinate of the font's bounding box.yMax
[ number ] (From ASCFont.BoundingBox) The maximum y-coordinate of the font's bounding box.
ASCFont.Triangle
Represents a triangle used to define the geometry of a glyph.
Fields:
v1
[ ASCFont.Coordinate ] The first vertex of the triangle.v2
[ ASCFont.Coordinate ] The second vertex of the triangle.v3
[ ASCFont.Coordinate ] The third vertex of the triangle.
ASCFont.Coordinate
Represents a coordinate in 2D space, typically used for defining the vertices of a triangle.
Fields:
[1]
[ number ] The x-coordinate of the point.[2]
[ number ] The y-coordinate of the point.
Functions
getFontInfo
sc.ascfont.getFontInfo( fontName )
Gets information/data about the font
Arguments:
- fontName [ string ] Name of the font
Returns:
- [ ASCFont ] The font data.
- [ string? ] The error message (if any)
calcTextSize
sc.ascfont.calcTextSize( fontName, text, fontSize, rotation )
Calculates text size, No error handling provided.
Arguments:
- fontName [ string ] The name of the font
- text [ string ] The text
- fontSize [ number ] The size of the font
- rotation [ number ] The rotation
Returns:
- [ number ] width The width the font consumes
- [ number ] hegiht The height the font consumes
drawTextSafe
sc.ascfont.drawText( display, xOffset, yOffset, text, fontName, color, rotation, fontSize, colorToggled )
Draws text to a display
Arguments:
- display [ Display ] The display
- xOffset [ number ] The x-coordinate
- yOffset [ number ] The y-coordinate
- text [ string ] The text to draw
- fontName [ string ] The name of the font
- color [ string|Color ] The color of the text to set
- rotation [ number? ] The rotation
- fontSize [ number ] The size of the font to use
- colorToggled [ boolean? ] If it should support colors or not in text.
getFontNames
sc.ascfont.getFontNames()
Gets all loaded font names.
Returns:
- [ string[] ] All font names.